const { app, BrowserWindow, globalShortcut } = require("electron");
const path = require("path");
// const app = electron.app; // 引用app
// const BrowserWindeo = electron.BrowserWindow; // 窗口引用

const shortcutArr = [
  {
    name: "ctrl + r",
    fn(win) {
      win.reload();
    },
  },
  {
    name: "ctrl + e",
    fn(win) {
      const is = win.isDevToolsOpened();

      if (is) {
        win.closeDevTools();
      } else {
        win.openDevTools();
      }
    },
  },
];

// 当 app 启动之后执行窗口创建等操作
app.whenReady().then(() => {
  const mainWin = new BrowserWindow({
    width: 1300,
    height: 900,
    icon: "assets/256px_ico.png",
    autoHideMenuBar: true,
  });

  // 加载 html页面
  mainWin.loadFile(path.join(__dirname, "../dist/index.html"));

  shortcutArr.forEach((item) => {
    const is = globalShortcut.register(item.name, () => {
      item.fn(mainWin);
    });
  });
});
